import requests
import execjs

with open('JS.js', 'r', encoding='utf-8') as f:
    js_code = f.read()

BASE_URL = 'https://spa2.scrape.center'
INDEX_URL = BASE_URL + '/api/movie/?limit={limit}&offset={offset}&token={token}'
MAX_PAGE = 10
LIMIT = 10
# 获取JavaScript运行环境，并传递给它读取到的js文件内容
js = execjs.compile(js_code)

for i in range(MAX_PAGE):
    offset = i * LIMIT
    token = js.call('get_token', '/api/movie', offset)
    index_url = INDEX_URL.format(limit=LIMIT, offset=offset, token=token)
    response = requests.get(index_url)
    print('response', response.json())